package _220322;

import java.util.Scanner;

/**
 * @author ShadowLim
 * @create 2022-03-22-8:56
 */
public class _123 {
    static int N = (int)2e6;
    static long[] a = new long[N];

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int t = scanner.nextInt();
        for (int i = 1; i < N; i++) {
            a[i] = a[i - 1] + sum(i);   // 前 i 段区间之和
        }
        while (t-- > 0) {
            long l = scanner.nextLong();
            long r = scanner.nextLong();
            System.out.println(ans(r) - ans(l - 1));
        }
    }

    /**
     * 前缀和:前 x 个数之和
     * @param x
     * @return
     */
    private static long ans(long x) {
        if (x == 0) {
            return 0;
        }
        if (x == 1) {
            return 1;
        }
        long y = find(x);   // 第 x 个区间的右边界
        return a[(int)y] + sum(x - sum(y));
    }

    /**
     * 第 x 个连续数字区间（即[1,2,3,4, ... ,x - 1, x]）之和
     * @param x
     * @return
     */
    private static long sum(long x) {
        return x * (x + 1) / 2;
    }

    /**
     * 二分查找第 x 个区间
     * @param x
     * @return
     */
    private static long find(long x) {
        long l = 1;
        long r = (long)3e6;
        while (l < r) {
            long mid = l + (r - l) / 2 + 1;
            if ((mid + 1) * mid / 2 < x) {
                l = mid;
            } else {
                r = mid - 1;
            }
        }
        return l;   // l == r
    }
}
